function getTwoPointAngle(o_latlngs, latlngs) {
    let A = new MyLatLng(o_latlngs[0], o_latlngs[1]);
    let B = new MyLatLng(latlngs[0], latlngs[1]);
    return getAngle(B, A);

}

function getMyLatLng(A, distance, angle) {
    let dx = distance * 1000 * Math.sin(Math.toRadians(angle));
    let dy = distance * 1000 * Math.cos(Math.toRadians(angle));
    let bjd = (dx / A.Ed + A.m_RadLo) * 180.0 / Math.PI;
    let bwd = (dy / A.Ec + A.m_RadLa) * 180.0 / Math.PI;
    return new MyLatLng(bjd, bwd);
}


function getAngle(A, B) {
    let dx = (B.m_RadLo - A.m_RadLo) * A.Ed;
    let dy = (B.m_RadLa - A.m_RadLa) * A.Ec;
    let angle = 0.0;
    angle = Math.atan(Math.abs(dx / dy)) * 180.0 / Math.PI;
    let dLo = B.m_Longitude - A.m_Longitude;
    let dLa = B.m_Latitude - A.m_Latitude;
    if (dLo > 0 && dLa <= 0) {
        angle = (90.0 - angle) + 90;
    } else if (dLo <= 0 && dLa < 0) {
        angle = angle + 180.0;
    } else if (dLo < 0 && dLa >= 0) {
        angle = (90.0 - angle) + 270;
    }
    return angle;
}

class MyLatLng {
    constructor(lng, lat) {
        const Rc = 6378137; // 赤道半径
        const Rj = 6356725; // 极半径
        // 经度转为度分秒
        this.m_LoDeg = lng;
        this.m_LoMin = ((lng - this.m_LoDeg) * 60);
        this.m_LoSec = (lng - this.m_LoDeg - this.m_LoMin / 60.0) * 3600;
        // 纬度转为度分秒
        this.m_LaDeg = lat;
        this.m_LaMin = ((lat - this.m_LaDeg) * 60);
        this.m_LaSec = (lat - this.m_LaDeg - this.m_LaMin / 60.0) * 3600;
        this.m_Longitude = lng;
        this.m_Latitude = lat;
        this.m_RadLo = lng * Math.PI / 180.0; // 经度弧度
        this.m_RadLa = lat * Math.PI / 180.0; // 纬度弧度
        this.Ec = Rj + (Rc - Rj) * (90.0 - this.m_Latitude) / 90.0;
        this.Ed = this.Ec * Math.cos(this.m_RadLa);
    }

}


export default getTwoPointAngle